goog.require('goog.dom');
goog.require('goog.array');
goog.require('PhotoManager');
goog.require('Editor');

goog.provide('Catalog');

/**
 * @constructor
 */
Catalog = function(catalogAlbumId, catalogUserId, pageSize) {
    this.catalogAlbumId = catalogAlbumId;
    this.catalogUserId = catalogUserId;
    this.pageSize = pageSize;

    this.currentPageNumber = -1;
    this.startEntryIndex = -1;
    this.endEntryIndex = -1;

    this.photoManager = null;
};


Catalog.prototype.start = function() {
    // Fire off the photo manager.
    this.photoManager = new PhotoManager(
	this.catalogAlbumId, this.catalogUserId, this.pageSize);
    this.photoManager.load(goog.bind(this.loadCallback_, this));
};

Catalog.prototype.reportError = function(message) {
    goog.dom.setTextContent(goog.dom.getElement('error-panel'), message);
};

Catalog.prototype.loadCallback_ = function(success) {
    if (!success) {
	this.reportError("Could not load catalog.");
	return;
    }
    goog.array.forEach(this.photoManager.currentPhotos,
		       goog.bind(function(p) { this.loadPhoto(p); }, this));
};

Catalog.prototype.loadPhoto = function(photo) {
    var e = new Editor(photo);
    e.show();
};

goog.exportSymbol('Catalog', Catalog);
goog.exportProperty(Catalog.prototype, 'start', Catalog.prototype.start);
